﻿using System;
using System.IO;

namespace Inovout.File
{
    public class ConfigFile
    {
        private static readonly string extensionName = "config";
        private static readonly string path = "Configs";
        private string name;

        public string FulLName
        {
            get 
            {
                return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("{0}\\{1}.{2}", path, name, extensionName));
            }
        }
        
        private ConfigFile()
        {
        }

        public ConfigFile(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            this.name = name;
        }

        public bool Exists()
        {
            
            return System.IO.File.Exists(FulLName);
        }
        public  void Write(Stream stream)
        {
            string configFolderName = Path.GetDirectoryName(FulLName);
            if (!Directory.Exists(configFolderName))
            {
                Directory.CreateDirectory(configFolderName);
            }
            using (FileStream fileStream = new FileStream(FulLName, FileMode.CreateNew, FileAccess.Write, FileShare.None))
            {
                fileStream.Write(stream);
            }

        }

    }
}
